import os


def configure_app(app):
    # 获取应用根目录的绝对路径
    base_dir = os.path.abspath(os.path.dirname(__file__))

    # 使用绝对路径定义uploads文件夹位置
    app.config["UPLOAD_FOLDER"] = os.path.join(base_dir, "uploads")
    app.config["ALLOWED_EXTENSIONS"] = {"png", "jpg", "jpeg", "gif"}

    # 确保uploads目录存在
    if not os.path.exists(app.config["UPLOAD_FOLDER"]):
        os.makedirs(app.config["UPLOAD_FOLDER"])
        print(f"Created uploads folder at: {app.config['UPLOAD_FOLDER']}")
    else:
        print(
            f"Using existing uploads folder at: {app.config['UPLOAD_FOLDER']}")
